var express = require('express');
const query = require('./db');
var router = express.Router();
/* GET users listing. */
router.get('/', function (req, res, next) {
  res.send('测试接口');
});

// 接口
router.get('/test', function (req, res, next) {
  let sql = "select * from `tb_stu`"
  // res.send('测试接口1')
  query(sql, function (err, rows) {
    console.log(rows);
    if (err) {
      var data = {
        code: -1,
        data: null,
        isSuccess: false,
        msg: err
      }
    } else {
      var data = {
        code: 0,
        data: rows,
        isSuccess: true,
        msg: "请求成功"
      }
    }
    res.json(data)
  })
})
router.get('/add', function (req, res, next) {
  let sql = "insert into `tb_stu` (stu_id,stu_name,sex,password,major,grade,class) values('201761311','啊啊','女','a123123','计算机科学与技术','2017','5')"
  // res.send('测试接口1')
  query(sql, function (err, rows) {
    console.log(rows);
    if (err) {
      var data = {
        code: -1,
        data: null,
        isSuccess: false,
        msg: err
      }
    } else {
      var data = {
        code: 0,
        data: rows,
        isSuccess: true,
        msg: "请求成功"
      }
    }
    res.json(data)
  })
})

module.exports = router;
